<?php
namespace App\Http\Controllers;

use App\Models\Scene;
use App\Models\Food;
use App\Models\Comment;
use Illuminate\Support\Facades\Schema;

class SceneController extends WxBaseController{
    protected $except=['index','show','getFoods','search'];
    public function index($order='recommended',$num=10){
        if(request()->page){
            $scenes = Scene::orderBy($order,'desc')->simplePaginate($num);
        }else{
            $scenes = Scene::orderBy($order,'desc')->get();
        }
        editImageUrl($scenes);
        return $this->apiReturn(true,'success',$scenes);
    }
    public function show($id){
        $scene = Scene::where('id',$id);
        //更新浏览量
        if(Schema::hasColumn('scenes', 'watch')){
            $scene->increment('watch');
        };
        $arr = $scene->get();
        editImageUrl($arr);
        return $this->apiReturn(true,'success',$arr);
    }
    public function search($input){
        $arr=Scene::where('title', 'like', '%'.$input.'%')->get();
        editImageUrl($arr);
        return $this->apiReturn(true,'success',$arr);
    }
    public function getFoods($id){
        $foods = Food::where('scene_id','=',$id)->get();
        editImageUrl($foods);
        return $this->apiReturn(true,'success',$foods);
    }

}